home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / ixnet / ndbm.c < prev    next >
C/C++ Source or Header  |  1996-03-13  |  4KB  |  196 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * Margo Seltzer.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Redistributions in binary form must reproduce the above copyright
  14.  *    notice, this list of conditions and the following disclaimer in the
  15.  *    documentation and/or other materials provided with the distribution.
  16.  * 3. All advertising materials mentioning features or use of this software
  17.  *    must display the following acknowledgement:
  18.  *    This product includes software developed by the University of
  19.  *    California, Berkeley and its contributors.
  20.  * 4. Neither the name of the University nor the names of its contributors
  21.  *    may be used to endorse or promote products derived from this software
  22.  *    without specific prior written permission.
  23.  *
  24.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  25.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  30.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  31.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  33.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34.  * SUCH DAMAGE.
  35.  */
  36.  
  37. #if defined(LIBC_SCCS) && !defined(lint)
  38. static char sccsid[] = "@(#)ndbm.c      5.7 (Berkeley) 6/17/91";
  39. #endif /* LIBC_SCCS and not lint */
  40.  
  41. /*
  42.     This package provides a dbm compatible interface to the new hashing
  43.     package described in db(3)
  44. */
  45.  
  46. #include <sys/param.h>
  47. #include <ndbm.h>
  48. #include <db.h>
  49. #include <stdio.h>
  50. #include <string.h>
  51. #include "hash.h"
  52.  
  53. /*
  54.     return    *DBM on success
  55.         NULL on failure
  56. */
  57. DBM *
  58. dbm_open( file, flags, mode )
  59. const char    *file;
  60. int    flags;
  61. int    mode;
  62. {
  63.     HASHINFO    info;
  64.     char path[MAXPATHLEN];
  65.  
  66.     info.bsize = 1024;
  67.     info.ffactor = 5;
  68.     info.nelem = 1;
  69.     info.cachesize = NULL;
  70.     info.hash = NULL;
  71.     info.lorder = 0;
  72.     (void)strcpy(path, file);
  73.     (void)strcat(path, DBM_SUFFIX);
  74.     return( hash_open ( path, flags, mode, &info ) );
  75. }
  76.  
  77. void
  78. dbm_close(db)
  79. DBM    *db;
  80. {
  81.     (void)(db->close) (db);
  82. }
  83.  
  84. /*
  85.     Returns    DATUM on success
  86.         NULL on failure
  87. */
  88. datum
  89. dbm_fetch( db, key )
  90. DBM    *db;
  91. datum    key;
  92. {
  93.     int status;
  94.     datum    retval;
  95.  
  96.     status = (db->get) ( db, (DBT *)&key, (DBT *)&retval, 0 );
  97.     if ( status ) {
  98.     retval.dptr = NULL;
  99.     retval.dsize = 0;
  100.     }
  101.     return(retval);
  102. }
  103.  
  104. /*
  105.     Returns    DATUM on success
  106.         NULL on failure
  107. */
  108. datum
  109. dbm_firstkey(db)
  110. DBM    *db;
  111. {
  112.     int status;
  113.     datum    retkey;
  114.     datum    retdata;
  115.  
  116.     status = (db->seq) ( db, (DBT *)&retkey, (DBT *)&retdata, R_FIRST );
  117.     if ( status ) {
  118.     retkey.dptr = NULL;
  119.     }
  120.     return(retkey);
  121. }
  122. /*
  123.     Returns    DATUM on success
  124.         NULL on failure
  125. */
  126. datum
  127. dbm_nextkey(db)
  128. DBM    *db;
  129. {
  130.     int status;
  131.     datum    retkey;
  132.     datum    retdata;
  133.  
  134.     status = (db->seq) ( db, (DBT *)&retkey, (DBT *)&retdata, R_NEXT );
  135.     if ( status ) {
  136.     retkey.dptr = NULL;
  137.     }
  138.     return(retkey);
  139. }
  140.  
  141. /*
  142.     0 on success
  143.     <0 failure
  144. */
  145. int
  146. dbm_delete(db, key)
  147. DBM    *db;
  148. datum    key;
  149. {
  150.     int status;
  151.  
  152.     status = (db->del)( db, (DBT *)&key, 0 );
  153.     if ( status ) {
  154.     return(-1);
  155.     } else {
  156.     return(0);
  157.     }
  158. }
  159.  
  160. /*
  161.     0 on success
  162.     <0 failure
  163.     1 if DBM_INSERT and entry exists
  164. */
  165. int
  166. dbm_store(db, key, content, flags)
  167. DBM    *db;
  168. datum    key;
  169. datum    content;
  170. int    flags;
  171. {
  172.     return ((db->put)( db, (DBT *)&key, (DBT *)&content,
  173.             (flags == DBM_INSERT) ? R_NOOVERWRITE : 0 ));
  174. }
  175.  
  176. int
  177. dbm_error(db)
  178. DBM    *db;
  179. {
  180.     HTAB    *hp;
  181.  
  182.     hp = (HTAB *)db->internal;
  183.     return ( hp->tab_errno );
  184. }
  185.  
  186. int
  187. dbm_clearerr(db)
  188. DBM    *db;
  189. {
  190.     HTAB    *hp;
  191.  
  192.     hp = (HTAB *)db->internal;
  193.     hp->tab_errno = 0;
  194.     return ( 0 );
  195. }
  196.